<?php
namespace console\controllers;

use yii\console\Controller;
use Yii;

/**
 * 工具
 */
class ToolsController extends Controller
{
    /**
     * 密码生成
     */
    public function actionPassword(){
        echo Yii::$app->security->generateRandomString(16);
    }

    /**
     * 转义
     */
    public function actionZhuangYi(){
        $extData = '{"data_extra":{"share_nickname":"\ud83c\udf44","share_openid":"o_3WB4qyWVz1gDTalY9gYmwwY-jw","payer_nickname":"\ud83c\udf44","payer_openid":"o_3WB4qyWVz1gDTalY9gYmwwY-jw"}}';

        //$extData = '{"share_nickname":"\"\\ud83c\\udf44\"","terminal_unique_no":"wxminiprogram","payer_nickname":"\"\\ud83c\\udf44\"","share_openid":"o_3WB4qyWVz1gDTalY9gYmwwY-jw","client_type":"miniprogram","notify_url":"http://b.020leader.com/business-platform/payment/remote-collection/notify","pay_mch_id":"4821014675","payer_openid":"o_3WB4qyWVz1gDTalY9gYmwwY-jw"}';
        
        $extData = json_decode($extData,true);
        //$extData = ['data_extra' => $extData];
        //var_dump($extData);
        $extData['data_extra']['share_nickname'] = trim(json_encode($extData['data_extra']['share_nickname']),'"');
        $extData['data_extra']['payer_nickname'] = trim(json_encode($extData['data_extra']['payer_nickname']),'"');
        var_dump($extData['data_extra']['share_nickname']);
        echo json_encode($extData);
    }

    /**
     * 反转义
     */
    public function actionFangZhuangYi(){
        $extData = '{"share_nickname":"\\ud83c\\udf44","terminal_unique_no":"wxminiprogram","payer_nickname":"\\ud83c\\udf44","share_openid":"o_3WB4qyWVz1gDTalY9gYmwwY-jw","client_type":"miniprogram","notify_url":"http://b.020leader.com/business-platform/payment/remote-collection/notify","pay_mch_id":"4821014675","payer_openid":"o_3WB4qyWVz1gDTalY9gYmwwY-jw"}';
        $extData = json_decode($extData,true);
        echo $extData['share_nickname'];
    }

    public function actionJson(){
        $json = '{"public_key":"MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAkw03IXdCsLHX+8f32pQym905K0PodgDmHbwCd+EJ4eT0KEXEQU2M09qmtIvrh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Jty6xQQJ+Aq4pOMa+ndqo5GpzNpo1qgz0ClMRVW+UEZ5hsV4RphTyttRFCXlUB1BbTjBv+oiBCdeaC4p\/9GNpR+TUi7kOfVuWhCthZIT5DCzV6VxygHcAAODMvKKxTP7A059CtnLuIl7hsmrybGtQaMozLq+ZmwqL65CBpe\/eiA9RSn3Gpt1OCwIDAQAB","redirect_url":"https:\/\/quan.020leader.com"}
';
        $data = json_decode($json, true);
        //var_dump($data);
        //echo "\n\n-----BEGIN RSA PRIVATE KEY-----\n" . wordwrap($data['private_key'], 64, "\n", true) . "\n-----END RSA PRIVATE KEY-----";

        //echo "\n\n-----BEGIN PUBLIC KEY-----\n" . wordwrap($data['alipay_public_key'], 64, "\n", true) . "\n-----END PUBLIC KEY-----";


        $publicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDDI6d306Q8fIfCOaTXyiUeJHkrIvYISRcc73s3vF1ZT7XN8RNPwJxo8pWaJMmvyTn9N4HQ632qJBVHf8sxHi/fEsraprwCtzvzQETrNRwVxLO5jVmRGi60j8Ue1efIlzPXV9je9mkjzOmdssymZkh2QhUrCmZYI/FCEa3/cNMW0QIDAQAB";

        $ALIPRIVATEKEY = "MIICeAIBADANBgkqhkiG9w0BAQEFAASCAmIwggJeAgEAAoGBANFUfZISOea3EHVq" .
            "fcglL8gZ0fxIYtlDqXYwxoVMn8U7fQoWK9OBA6OSwPCFS7YMMPDl6D7m+oEwg8SA" .
            "8DZJTE8ygf+IDxDaFOb4zZAlsq3mTCzTaFTLq0kLKRiXXrJTQgnapLq3OtWGySwv" .
            "AMxvXspcmeySJM8Fp3qaJWRxOQ+nAgMBAAECgYEAuQHVoX4eUnzFPSELXhMPseiw" .
            "ICrRwnf8lArzyeg45RZ4oquJvHqv/qe7glgs3A7WSnLH2qBGElwQeWID69bIazT+" .
            "sl8fX+/bjSvqfbBx62JjDs3ZnEn3nNbNScxz7jDRS5D6R58ioDb1Kk3ldshg6bJI" .
            "vsvb+Zykunf1VBj7mNECQQDx8f/+32gf5mj37eZvKmE3nVxVrmQF4XQnp8BXT3ug" .
            "7ro4PVMM3YV22f8Wa7OowHXwF4D+fdULHMUHz/THeCp7AkEA3X128LcXw2dIAWNL" .
            "FRKDqZtoEP+8g/hZpZxWe8VyBhlyONf20scJJR3MflowAbYyLuxCYdRemH4txs5F" .
            "g95txQJBANWU6oYWthajEjr72pZ79QJheedxYX8HfcCcB+GLmvmAhQesqyoKTA2V" .
            "d+hU/26TKAng1dDTSETdCtpQrCeCXw0CQGdRfmkdT3V0OS+EjOKgh1BX0PyU/vAk" .
            "qlTJj8IewWi89/4yJ8380HRC6UBLe7dgsRoYVYLjGNlTirEBSYYQ/O0CQQDgzpkn" .
            "u+trQ5KsjGzIORp2+N+VMFivQ8nekxEm6v8vV4qJwpqu4hLmbZI0n/22TYskPdEl" .
            "JyJ9WUAve14Z/wXv";
        var_dump($publicKey);
        echo "\n\n-----BEGIN PUBLIC KEY-----\n" . wordwrap($publicKey, 64, "\n", true) . "\n-----END PUBLIC KEY-----";
        echo "\n\n-----BEGIN RSA PRIVATE KEY-----\n" . wordwrap($ALIPRIVATEKEY, 64, "\n", true) . "\n-----END RSA PRIVATE KEY-----";

        
    }

    public function actionCmd(){
        echo exec('php yii tools/proc-test', $output) . PHP_EOL;
        var_dump($output);
    }

    public function actionProcTest(){
        echo "start run" . PHP_EOL;
        sleep(60);
        echo "end run" . PHP_EOL;
    }
}